﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VacationDaysDatabase;
using VacationDaysCommons;
using System.Collections.ObjectModel;

namespace VacationDaysClient
{
    /// <summary>
    /// Interaction logic for AdminWindow.xaml
    /// </summary>
    public partial class AdminWindow : Window
    {
        public ObservableCollection<VDEmployee> _employeesCollection = new ObservableCollection<VDEmployee>();
        public ObservableCollection<VDEmployee> EmployeeCollection { get { return _employeesCollection; } }

        private void RefreshUsers()
        {

            using (VDUserServiceClient vu = new VDUserServiceClient())
            {
                var employees = vu.GetEmployees(0, 100);
                _employeesCollection.Clear();
                foreach (var employee in employees)
                {
                    _employeesCollection.Add(employee);
                }
            }
        }

        public AdminWindow()
        {
            RefreshUsers();
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
           
          
        }

        private void usersList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            VDEmployee existingUser = (VDEmployee)usersList.SelectedItem;
            Application.Current.MainWindow = new RegisterUser(existingUser);
            bool? success = Application.Current.MainWindow.ShowDialog();
            if (success != null && success == true)
            {
                RefreshUsers();
            }
        }
    }
}
